package com.example.base;

import lombok.Data;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

import java.io.Serializable;

/**
 *  接口返回结果封装
 *      code 返回码
 *      message 返回信息
 *      data 返回数据
 * @param <T>
 */
@Data
public class Result<T> implements Serializable {
    private int status;
    private String message;
    private Object data;

    public <T> Result(int status, String message, T data) {
        this.status = status;
        this.message = message;
        this.data = data;
    }

    public ResponseEntity<Object> Ok(T data) {
        Result result = new Result(ResultStatus.OK.getStatus(), ResultStatus.OK.getMessage(), data);
        return new ResponseEntity<Object>(result,HttpStatus.OK);
    }

    public static ResponseEntity<Object> Ok() {
        Result result = new Result(ResultStatus.OK.getStatus(), ResultStatus.OK.getMessage(), null);
        return new ResponseEntity<Object>(result,HttpStatus.OK);
    }

//    public static ResponseEntity<Object> error(String message) {
//        Result result = new Result(ResultStatus.ERROR.getStatus(), message, null);
//        return new ResponseEntity<Object>(result,HttpStatus.OK);
//    }
//
//    public static ResponseEntity<Object> error() {
//        Result result = new Result(ResultStatus.ERROR.getStatus(), ResultStatus.ERROR.getMessage(), null);
//        return new ResponseEntity<Object>(result,HttpStatus.OK);
//    }

    public Result() {
    }
}
